<template>
     项目名称: <input type="text" v-model="data.Iname">
    项目总金额: <input text="text" v-model="data.Iminsum">-<input type="text" v-model="data.Imaxsum">
    <button @click="ShowInvest">查询</button>
<table>
    <tr>
        <td>投资名称</td>
        <td>投资总额度</td>
        <td>已投资额度</td>
        <td>剩余额度</td>
        <td>投资人数</td>
        <td>操作</td>
    </tr>
    <tr v-for="i in info">
        <td>{{ i.Iname }}</td>
        <td>{{ i.Isum }}</td>
        <td>{{ i.Iyprice }}</td>
        <td>{{ i.Isprice }}</td>
        <td>{{ i.Inum }}</td>
        <td><a href="#" @click="Delete(i.Iid)">删除</a>
            <a href="#" @click="SelectById(i.Iid)">修改</a>
        </td>
    </tr>
</table>
</template>
<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
const router=useRouter();
const data=ref({
    Iname:'',
    Iminsum:"",
    Imaxsum:""
})
const info =ref(
    [
        {
            Iid:0,
            Iname:'',
            Isum:'',
            Iyprice:'',
            Isprice:'',
            Inum:''
        }]
)
onMounted(()=>{
    ShowInvest();
})


const ShowInvest=()=>{
    axios.get('https://localhost:44382/Api/Lx/ShowInvest',
        {
            params:{
                Iname:data.value.Iname,
                Iminsum:data.value.Iminsum,
                Imaxsum:data.value.Imaxsum
            }
        }
    )
    .then(res=>{
        info.value=res.data;
    })
    .catch(err=>{
        console.log(err);
    })
}
const Delete=(Iid:number)=>{
    if(!confirm("确定要删除吗？")){
        return;
    }
    axios.get("https://localhost:44382/api/Lx/DeleteById",
        {
            params:{
                Iid:Iid
            }
        }
    )
    .then(res=>{
        if(res.data>0){
            alert("删除成功");
            ShowInvest();
        }
        else{
            alert("删除失败");
            ShowInvest();
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
const SelectById=(Iid:number)=>{
    localStorage["Iid"]=Iid
    router.push({
        name:"Update",
        params:{
            Iid:Iid
        }
    })
}



</script>